import { mapState, mapActions, mapMutations, mapGetters } from 'vuex'

export default {
  computed: {
    // ...mapState('user', ['deviceId']),
		...mapGetters('user', ['getUserInfo'])
  },
  methods: {
    ...mapActions('user', ['loginForWexin', 'loginForPhone', 'loginForPassword', 'getUserInfoFn','loginForPhoneAndPwd']),
		...mapMutations('global', ['setDeviceInfo']),
    
    // 跳转卡友之家服务协议
    onKyzjServiceProtocol() {
      uni.navigateTo({
        url: '/pages/webview/webview?url=' + 'https://passenger-car-uat-1301027390.cos.ap-beijing.myqcloud.com/file/statement/index.html#/pages/index/agreement',
        success: (res) => {
          res.eventChannel.emit('setTitle', '用户协议')
        }
      })
    },
    
    // 跳转卡友之家隐私政策
    onKyzjPrivacyPolicy() {
      uni.navigateTo({
        url: '/pages/webview/webview?url=' + 'https://passenger-car-uat-1301027390.cos.ap-beijing.myqcloud.com/file/statement/index.html#/pages/index/privacy'
      })
    },
    
    // 跳转微信登录页
    toWxLogin() {
      uni.navigateTo({
        url: `/authPack/login/wxLogin`
      })
    },
    
    // 跳转密码登录页
    toPasswordLogin() {
      const phone = (this.formData && this.formData.phone) || ''
      uni.redirectTo({
        url: `/authPack/login/passwordLogin?phone=${phone}`
      })
    },
    
    // 跳转手机短信登录页
    toPhoneLogin() {
      const phone = (this.formData && this.formData.username) || ''
      uni.redirectTo({
        url: `/authPack/login/phoneLogin?phone=${phone}`
      })
    },
    
    // 跳转忘记密码页
    toForgotPassword() {
      uni.navigateTo({
        url: '/authPack/login/forgotPassword'
      })
    },
    
    // 跳转首页
    toIndex() {
      let userInfo = uni.getStorageSync('userInfo') || {}
      //首次登录且未添加姓名时
      if (userInfo && userInfo.firstLogin === 'Y' && userInfo.name === '') {
        uni.redirectTo({
          url: `/authPack/improve/information`
        })
      } else {
        uni.switchTab({
          url: '/pages/index/index/index'
        })
      }
			// 埋点
			this.$uma.trackEvent('login');
			this.autoReport({
				pageName: '登录页',
				eventCode: 'login',
			})
			
			// 清除第三方渠道登录信息
			uni.removeStorageSync('AppLaunchQuery')
    }
  },
}